import { getStore } from '@/utils/store'
const userInfo = getStore('userInfo') || {}
export const formProjectConfig = (subsidyType?: string | number, applySource?: number) => {
	return {
		inline: false,
		showBtn: false,
		labelPosition: 'top',
		labelWidth: '100px',
		column: [
			{
				label: '选择申请补贴类型',
				prop: 'subsidyType',
				propName: 'subsidyTypeLabel',
				type: 'remoteSelect',
				api: 'getDictItemList',
				code: 'SUBSIDY_TYPE',
				filterKey: 'value',
				disabled: true,
				multiple: false,
				span: 24,
				rules: [{ required: true, message: '请选择申请补贴类型' }],
			},
			{
				type: 'autoSelect',
				label: '名称',
				prop: 'subsidyProjectId',
				propName: 'subsidyProjectName',
				filterLabel: 'projectName',
				filterKey: 'id',
				api: 'view_ofsSubsidyProject_page',
				paramsObj: {
					subsidyType,
					isAuthFilter: false,
					organizationId: userInfo.organizationId,
				},
				span: 24,
				rules: [{ trigger: 'change', required: true, message: '请选择项目名称' }],
				change: (item, form) => {
					form.subsidyApplyConfigId = item.subsidyApplyConfigId
				},
			},
			{
				label: '第一笔',
				prop: 'firstId',
				type: 'autoSelect',
				api: 'view_ofsSubsidyApply_page',
				filterKey: 'id',
				filterLabel: 'subsidyProjectName',
				tipLabel: 'belongDateLabel',
				multiple: false,
				display: applySource == 2 && subsidyType == 1,
				paramsObj: {
					grantStatus: 1,
					applyType: 5,
					subsidyType: 1,
					bedApplyType: 1,
				},
				span: 24,
				rules: [{ required: true, message: '请选择第一笔补贴申请' }],
			},
		],
	}
}

export const tableConfig = () => {
	const userInfo = getStore('userInfo') || {}
	// 用户类型;1：大众用户，2：平台管理员，3：政务用户,4: 养老服务组织用户
	const classifyId = userInfo.classifyId

	const adminConfig = {
		stripe: true,
		border: true,
		maxHeight: '80vh',
		columns: [
			{
				label: '养老机构名称',
				prop: 'orgName',
			},
			{
				label: '星级',
				prop: 'organizationLevelLabel',
			},
			{
				label: '名称',
				prop: 'subsidyProjectName',
			},
			{
				label: '申请补贴类型',
				prop: 'subsidyTypeLabel',
			},
			{
				label: '申请年月',
				prop: 'belongDateLabel',
			},
			{
				label: '状态',
				prop: 'approvalStatus',
				custome: 'tag',
				dicData: [
					{ label: '驳回', value: -1, style: { color: '#FA3E3E', background: '#FFC4B1' } },
					{ label: '待提交', value: 1, style: { color: '#FF8800', background: '#FFF3E5' } },
					{ label: '审批中', value: 2, style: { color: '#00A870', background: '#C8FFB1' } },
					{ label: '审批通过', value: 3, style: { color: '#0052D9', background: '#D9E8FF' } },
					{ label: '已录入发放凭证', value: 4, style: { color: '#7106C2', background: '#E9CBFF' } },
					{ label: '已录入回执', value: 5, style: { color: '#7106C2', background: '#E9CBFF' } },
				],
			},
			{
				label: '状态说明',
				prop: 'approvalStatusLabel',
			},
			{
				label: '申请时间',
				prop: 'createTime',
			},
			{
				label: '操作',
				prop: 'menu',
				width: 300,
				fixed: 'right',
			},
		],
	}
	const orgConfig = {
		stripe: true,
		border: true,
		maxHeight: '80vh',
		columns: [
			{
				label: '名称',
				prop: 'subsidyProjectName',
			},
			{
				label: '申请补贴类型',
				prop: 'subsidyTypeLabel',
			},
			{
				label: '申请年月',
				prop: 'belongDateLabel',
			},
			{
				label: '状态',
				prop: 'approvalStatus',
				custome: 'tag',
				dicData: [
					{ label: '驳回', value: -1, style: { color: '#FA3E3E', background: '#FFC4B1' } },
					{ label: '待提交', value: 1, style: { color: '#FF8800', background: '#FFF3E5' } },
					{ label: '审批中', value: 2, style: { color: '#00A870', background: '#C8FFB1' } },
					{ label: '审批通过', value: 3, style: { color: '#0052D9', background: '#D9E8FF' } },
					{ label: '已录入发放凭证', value: 4, style: { color: '#7106C2', background: '#E9CBFF' } },
					{ label: '已录入回执', value: 5, style: { color: '#7106C2', background: '#E9CBFF' } },
				],
			},
			{
				label: '状态说明',
				prop: 'approvalStatusLabel',
			},
			{
				label: '申请人',
				prop: 'createUserName',
			},
			{
				label: '申请时间',
				prop: 'createTime',
			},
			{
				label: '操作',
				prop: 'menu',
				width: 300,
				fixed: 'right',
			},
		],
	}
	return classifyId == 2 || classifyId == 3 ? adminConfig : orgConfig
}

const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '100px',
	column: [
		{
			label: '名称',
			prop: 'subsidyProjectName',
			type: 'input',
			span: 8,
		},
		{
			label: '所属区域',
			prop: 'authAreas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '申请时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			dateType: 'datetimerange',
			span: 8,
			format: 'YYYY年MM月DD日 HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
		},
		{
			label: '养老机构名称',
			prop: 'orgName',
			type: 'input',
			span: 8,
		},
		{
			label: '审批结果',
			prop: 'approvalStatus',
			type: 'select',
			span: 8,
			dicData: [
				{ label: '待提交', value: 1 },
				{ label: '审批中', value: 2 },
				{ label: '审批通过', value: 3 },
				{ label: '驳回', value: 4 },
			],
		},
		{
			label: '申请人',
			prop: 'createUserName',
			type: 'input',
			span: 8,
		},
	],
}
export const detailConfig: any = {
	inline: false,
	labelPosition: 'left',
	labelWidth: '200px',
	showBtn: false,
	column: [
		{
			label: '名称',
			prop: 'projectName',
			span: 24,
		},
		{
			label: '选择申请补贴类型',
			prop: 'subsidyType',
			propName: 'subsidyTypeLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'SUBSIDY_TYPE',
			filterKey: 'value',
			multiple: false,
			span: 24,
		},
		{
			label: '项目日期范围',
			prop: 'startToEnd',
			span: 24,
		},
		{
			label: '状态',
			prop: 'projectEnable',
			type: 'radio',
			dicData: [
				{ label: '开启', value: 1 },
				{ label: '关闭', value: 0 },
			],
			span: 24,
		},
		{
			label: '选择填报的养老服务组织',
			prop: 'organizationIdsLabel',
			span: 24,
		},
		{
			label: '选择申请配置信息',
			prop: 'subsidyApplyConfigName',
			span: 24,
		},
		{
			label: '是否开启自动申请',
			prop: 'autoApplyFlag',
			type: 'radio',
			dicData: [
				{ label: '开启', value: 1 },
				{ label: '关闭', value: 0 },
			],
			span: 24,
		},
		{
			label: '自动申请时限',
			prop: 'autoLimitDay',
			value: 0,
			display: false,
			type: 'input',
			span: 24,
		},
		{
			label: '选择审批配置信息',
			prop: 'workflowName',
			span: 24,
		},
		{
			label: '表单预览',
			prop: 'formPreview',
			span: 24,
		},
	],
}

const auth = {
	index: 'view_ofsSubsidyApply_page',
	add: 'view_ofsSubsidyApply_add',
	mulitSet: 'mulitSet',
	delete: 'view_ofsSubsidyApply_del',
	subsidy_report: 'view_downloadData_download',
	detail: 'view_ofsSubsidyApply_view',
}
export const baseConfig: any = {
	pageName: '申请管理',
	addLabel: '申请',
	dictcodes: ['SUBSIDY_TYPE'],
	rowKey: 'id',
	tipLabel: 'orgName',
	exportMqTopic: '/ning/export/',
	api: {
		index: 'view_ofsSubsidyApply_page',
		add: 'view_ofsSubsidyApply_add',
		export: 'view_ofsSubsidyApply_approval_exportApply',
		delete: 'view_ofsSubsidyApply_del',
		detail: 'view_ofsSubsidyApply_view',
		authArea: true,
		subsidy_report: 'view_downloadData_download',
	},
	auth,
	menuBtn: [
		{
			icon: '',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
			condition: '(row)=>row.approvalStatus == 1||row.approvalStatus == -1',
		},
	],
	dialogConfig: {
		width: '85%',
	},
	searchConfig,
	detailConfig,
}
